//
//  M4DeviceDataManager.swift
//  M4
//
//  Created by YuChuang on 2024/8/19.
//

import UIKit
import AdjustSdk

class M4DeviceDataManager: NSObject {
    
    static let m4DeviceShare = M4DeviceDataManager()
    
    var m4firstEnterTime: Int {
        get {
            return UserDefaults.standard.integer(forKey: "m4firstEnterTime")
        }
        set {
            let userDefaults = UserDefaults.standard
            userDefaults.set(newValue, forKey: "m4firstEnterTime")
            userDefaults.synchronize()
        }
    }
    
    var m4MQtjG: Int {
        get {
            return UserDefaults.standard.integer(forKey: "m4MQtjG")
        }
        set {
            let userDefaults = UserDefaults.standard
            userDefaults.set(newValue, forKey: "m4MQtjG")
            userDefaults.synchronize()
        }
    }
    
    var m4EPS: Int = 0
    
    var m4CVQs: Int {
        get {
            return UserDefaults.standard.integer(forKey: "m4CVQs")
        }
        set {
            let userDefaults = UserDefaults.standard
            userDefaults.set(newValue, forKey: "m4CVQs")
            userDefaults.synchronize()
        }
    }
    
    var m4XwMAiX: String = ""
    
    var ips: [String] = []
    var wifiName: String = ""
    
    var m4MjgIyPNRpq: Int {
        get {
//            let uptime = ProcessInfo.processInfo.systemUptime
//            var date = Date()
//            date = date.addingTimeInterval(-uptime)
//            let formatter = DateFormatter()
//            formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
//            return formatter.string(from: date)
            
            let uptime = ProcessInfo.processInfo.systemUptime
            let t = Date().timeIntervalSince1970 - uptime
            return Int(t)
        }
    }
    
    var m4Sus: String {
        get {
            let processInfo = ProcessInfo.processInfo
            let uptime = processInfo.systemUptime
            let formatter = DateComponentsFormatter()
            formatter.allowedUnits = [.hour, .minute, .second]
            formatter.unitsStyle = .full
            let uptimeString = formatter.string(from: uptime)
            return uptimeString ?? ""
        }
    }
    
    var m4FrnBuE: Int {
        get {
            UIDevice.current.isBatteryMonitoringEnabled = true
            let data = Int(UIDevice.current.batteryLevel * 100)
            return data
        }
    }
    
    var m4ZJDg: Int = M4IsRootResult == true ? 1 : 0
    
    var m4BntQavpE: String = UIDevice.current.systemVersion
    
    var m4RAQdnE = M4ScreenHeight*UIScreen.main.scale

    var m4MBhBDco = M4ScreenWidth*UIScreen.main.scale
    
    var m4ByVUptnWWYl: String = ""

    var m4FeEx: String = ""

    var m4PSr: String = ""//Adjust.idfa() ?? ""
    
    var m4LRHlRvSA: String = ""
    
    var mac: String = ""
    
    var m4KFVUV: String {
        get {
            let fileTotalSize: Int64 = m4diskTotalSize()
            return m4fileSizeToString(fileSize: fileTotalSize)
        }
    }

    var m4ECShpPNI: String {
        get {
            let fileAvailableSize: Int64 = m4diskAvailableSize()
            return m4fileSizeToString(fileSize: fileAvailableSize)
        }
    }

    var m4DORPa: String = ""

    var m4UlzQRcV: String = ""
    
    var m4CODS: Int {
        get {
            return UserDefaults.standard.integer(forKey: "m4CODS")
        }
        set {
            let userDefaults = UserDefaults.standard
            userDefaults.set(newValue, forKey: "m4CODS")
            userDefaults.synchronize()
        }
    }
    
    var m4QhnB: Int {
        get {
            return UserDefaults.standard.integer(forKey: "m4QhnB")
        }
        set {
            let userDefaults = UserDefaults.standard
            userDefaults.set(newValue, forKey: "m4QhnB")
            userDefaults.synchronize()
        }
    }
    
    var m4SSq: Int {
        get {
            return UserDefaults.standard.integer(forKey: "m4SSq")
        }
        set {
            let userDefaults = UserDefaults.standard
            userDefaults.set(newValue, forKey: "m4SSq")
            userDefaults.synchronize()
        }
    }
    
    var m4KEVROxIl: Int = 0
    var m4phoneBeginTime: Int = 0
    
    var m4NtQksYpPs: Int {
        get {
            UIDevice.current.isBatteryMonitoringEnabled = true
            let charging: Bool = UIDevice.current.batteryState == .charging
            if charging {
                return 1
            }
            else {
                return 0
            }
        }
    }
    
    var m4Giczr: String = "0"
    
    var m4QtWe: String = TimeZone.current.abbreviation() ?? ""
    
    var m4TNr: String = M4VPNConnected() == true ? "1" : "0"
    
    var m4KDtZZ: String {
        get {
            let userDefault = UserDefaults.standard
            let languages:NSArray = userDefault.object(forKey: "AppleLanguages") as! NSArray
            return languages.object(at: 0) as! String
        }
    }

    var m4FKlhJeXT: Int = Int(UIScreen.main.brightness)
    
    var m4GHPTPehkFK: String = m4getCountryCode()
    
    var m4FZYOZ: String = m4getNetworkCode()
    
    var m4TZfpuyuyvg: Int = 0
    
    var m4Auf: Int = m4isRunningOnSimulator()
    
    var m4VZh: String = m4getoperators()
    
    var m4RqI: Int = 0
    
    var m4PHPwi: String = ""//Adjust.idfa() ?? ""
    
    var m4GufgdRChqiI: Int = 0
    
    var m4CqFHWSP: Int = 100
    
    var m4Ozas: Int = ProcessInfo.processInfo.processorCount
    
    var m4BnnpqGY: String {
        get {
            let fileTotalSize: Int64 = m4diskTotalSize()
            return m4fileSizeToString(fileSize: fileTotalSize)
        }
    }
    
    var m4HMSLenjspX: String {
        get {
            let fileTotalSize: Int64 = m4diskTotalSize()
            let fileAvailableSize: Int64 = m4diskAvailableSize()
            let usedSize: Int64 = fileTotalSize - fileAvailableSize
            return m4fileSizeToString(fileSize: usedSize)
        }
    }
    
}
